package controller;

import entity.Emp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

//@Controller
@RestController
@RequestMapping("/ajax")
public class AjaxController {

//    @RequestMapping(value = "/validateUsername",produces = "text/plain;charset=utf-8")
//    public @ResponseBody String validateUsername(String username){
//        System.out.println("AjaxController.validateUsername()");
//
//        if("abc".equals(username)){
//            return "用户名已存在";
//        }
//        return "用户名可用";
//    }
//
//    @RequestMapping("/getEmp")
//    public @ResponseBody Emp getEmp(){
//        System.out.println("AjaxController.getEmp()");
//        Emp emp=new Emp();
//        emp.setId(1);
//        emp.setName("abc啊");
//        emp.setPassword("123");
//        emp.setEmail("a@a.com");
//        emp.setAge(23);
//        emp.setPhone("12345678");
//        return emp;
//    }


    @RequestMapping(value = "/validateUsername",produces = "text/plain;charset=utf-8")
    public String validateUsername(String username){
        System.out.println("AjaxController.validateUsername()");

        if("abc".equals(username)){
            return "用户名已存在";
        }
        return "用户名可用";
    }

    @RequestMapping("/getEmp")
    public Emp getEmp(){
        System.out.println("AjaxController.getEmp()");
        Emp emp=new Emp();
        emp.setId(1);
        emp.setName("abc啊");
        emp.setPassword("123");
        emp.setEmail("a@a.com");
        emp.setAge(23);
        emp.setPhone("12345678");
        return emp;
    }
}
